package com.net.wanjian.networkhospitalmanager.fragment;


import android.support.v7.widget.GridLayoutManager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.activity.VideoPlaybackActivity;
import com.net.wanjian.networkhospitalmanager.activity.dopsminicex.DopsMiniCexActivity;
import com.net.wanjian.networkhospitalmanager.activity.skilltrain.SkillTrainActivity;
import com.net.wanjian.networkhospitalmanager.activity.teacherevent.TeacherEventActivity;
import com.net.wanjian.networkhospitalmanager.adapter.HomeAdapter;
import com.net.wanjian.networkhospitalmanager.adapter.base.RecyclerBaseAdapter;
import com.net.wanjian.networkhospitalmanager.bean.HomeItemBean;
import com.net.wanjian.networkhospitalmanager.fragment.base.BaseFragment;
import com.net.wanjian.networkhospitalmanager.netstatus.NetUtils;
import com.net.wanjian.networkhospitalmanager.widge.RefreshRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Description:首页
 * Created by lidongcai on 2017/4/22.
 * Email:  lidongcaiocc@163.com
 */
public class HomeFragment extends BaseFragment {

    @BindView(R.id.home_recycler_list)
    RefreshRecyclerView homeRecyclerList;
    @BindView(R.id.top_back_layout)
    LinearLayout topBackLayout;
    @BindView(R.id.top_title_tv)
    TextView topTitleTv;

    private List<HomeItemBean> itemList = new ArrayList<>();
    private int[] res = new int[]{R.mipmap.icon_skill_training_png, R.mipmap.icon_teaching_behavior_png, R.mipmap.icon_video_png, R.mipmap.icon_gauge_with_test_png, R.mipmap.icon_public_events_png, R.mipmap.icon_rotation_scheduling_png};
    private String[] text = new String[]{"技能培训", "教学行为", "视频播放", "DOPSMINICEX","规培考试", "公共事件", "轮转排班"};
    private HomeAdapter mHomeAdapter;

    @Override
    protected void initView() {
        topBackLayout.setVisibility(View.GONE);
        topTitleTv.setText("首页");
        homeRecyclerList.setLayoutManager(new GridLayoutManager(mContext, 4));
//        homeRecyclerList.addItemDecoration(new HomeItemDecoration());
        homeRecyclerList.setRefreshMode(0);

        mHomeAdapter = new HomeAdapter(mContext);
        homeRecyclerList.setAdapter(mHomeAdapter);
        mHomeAdapter.setOnItemClickListener(new RecyclerBaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int pos) {
                switch (pos) {
                    case 0:
                        openActivity(SkillTrainActivity.class);
                        break;
                    case 1:
                        openActivity(TeacherEventActivity.class);
                        break;
                    case 2:
                        openActivity(VideoPlaybackActivity.class);
                        break;
                    case 3:
                        openActivity(DopsMiniCexActivity.class);
                        break;
                    default:
                        Toast.makeText(mContext, "此模块正在开发中。。。敬请期待", Toast.LENGTH_SHORT).show();
                }
            }
        });

        for (int i = 0; i < 4; i++) {
            itemList.add(new HomeItemBean(res[i], text[i]));
        }
        mHomeAdapter.setList(itemList);
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_home;
    }

    public static HomeFragment getInstance() {
        HomeFragment homeFragment = new HomeFragment();
        return homeFragment;
    }

    @Override
    protected void initData() {

    }

}
